﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity.Framework;
using System.Data.Objects;

namespace Business.Operations
{
    public class TakimOperation
    {
        private static HPDMASEntities db = new HPDMASEntities();

        public TakimOperation()
        {

        }

        public static List<Takim> TakimGetAll()
        {
            var takimListesi = db.Takim.ToList();
            return takimListesi;
        }

        public static Takim TakimGetByTakimId(int takimId)
        {
            var takim = (from c in db.Takim where c.TakimID == takimId select c).First();
            return takim;
        }

        public static void TakimDelete(int takimId)
        {
            //db.gsp_TakimDelete(takimId);
            Takim k = (from c in db.Takim where c.TakimID == takimId select c).First();
            db.DeleteObject(k);
            db.SaveChanges();
        }

        public static void TakimInsert(Takim takim)
        {
            db.Takim.AddObject(takim);
            db.SaveChanges();
        }

        public static List<string> TakimAdiGetBySehirId(int sehirId)
        {
            var takimAdi = (from c in db.TakimSehir where c.SehirID == sehirId select c.Takim.TakimAdi).ToList();
            return takimAdi;
        }

        public static int TakimIdGetByTakimAdi(string takimAdi)
        {
            var takimId = (from c in db.Takim where c.TakimAdi == takimAdi select c.TakimID).First();
            return takimId;
        }

        public static List<string> TakimAdiGetBySehirIdAndLigId(int sehirId, int ligId)
        {
            var takimAdi = db.TakimSehir.
                Where(c => c.SehirID == sehirId && c.Takim.LigID == ligId).
                Select(c => c.Takim.TakimAdi).ToList();
            return takimAdi;
        }
    }
}
